package Code.Test;

import java.util.ArrayList;

public class U1 {
    public static void main(String[] args) {
        //创建集合
        ArrayList<User> list = new ArrayList<>();

        User u1 = new User("001","zhangsan","123");
        User u2 = new User("002","lisi","456");
        User u3 = new User("003","wangwu","789");

        list.add(u1);
        list.add(u2);
        list.add(u3);

        System.out.println(find(list,"002"));
        System.out.println(getIndex(list,"004"));


    }
    public static boolean find(ArrayList<User> list,String id){
        return getIndex(list, id) > 0;
    }

    public  static int getIndex(ArrayList<User> list,String id){
        for (int i = 0; i < list.size(); i++) {
            String str = list.get(i).getId();
            if (id.equals(str)){
                return i;
            }
        }
        return -1;
    }
}
